
package com.jf.cloud.supplier.feign;

import com.jf.cloud.api.auth.constant.SysTypeEnum;
import com.jf.cloud.api.supplier.bo.SupplierDetailBO;
import com.jf.cloud.api.supplier.bo.SupplierSimpleBO;
import com.jf.cloud.api.supplier.feign.SupplierDetailFeignClient;
import com.jf.cloud.api.supplier.vo.SupplierApiDetailVO;
import com.jf.cloud.api.supplier.vo.SupplierApiUserVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.supplier.dto.SupplierDetailDTO;
import com.jf.cloud.supplier.model.SupplierDetail;
import com.jf.cloud.supplier.service.SupplierDetailService;
import com.jf.cloud.supplier.service.SupplierUserService;
import com.jf.cloud.supplier.vo.SupplierDetailVO;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author zz
 * @date 2020/11/23
 */
@RestController
@Hidden
public class SupplierDetailFeignController implements SupplierDetailFeignClient {

    @Autowired
    private SupplierDetailService supplierDetailService;
    @Autowired
    private MapperFacade mapperFacade;
    @Autowired
    private SupplierUserService supplierUserService;

//    @Override
//    public ServerResponseEntity<SupplierInfoInOrderVO> getSupplierInfoInOrderBySupplierId(Long supplierId) {
//        SupplierApiDetailVO supplierDetail = supplierDetailService.getBySupplierId(supplierId);
//        SupplierInfoInOrderVO supplierInfoInOrderVO = new SupplierInfoInOrderVO();
//        if (Objects.isNull(supplierDetail)) {
//            supplierInfoInOrderVO.setSupplierName("");
//            // 普通店
//            supplierInfoInOrderVO.setType(SupplierType.STOP.value());
//            return ServerResponseEntity.success(supplierInfoInOrderVO);
//        }
//        supplierInfoInOrderVO.setSupplierName(supplierDetail.getSupplierName());
//        supplierInfoInOrderVO.setType(supplierDetail.getType());
//        return ServerResponseEntity.success(supplierInfoInOrderVO);
//    }

    @Override
    public ServerResponseEntity<SupplierDetailBO> getSupplierBySupplierId(Long supplierId) {
        SupplierApiDetailVO supplierDetail = supplierDetailService.getBySupplierId(supplierId);
        if (Objects.isNull(supplierDetail)) {
            return ServerResponseEntity.success(new SupplierDetailBO());
        }
        return ServerResponseEntity.success(mapperFacade.map(supplierDetail, SupplierDetailBO.class));
    }

    @Override
    public ServerResponseEntity<Integer> countByMobile(String mobile) {
        return ServerResponseEntity.success(supplierDetailService.countByMobile(mobile));
    }

    @Override
    public ServerResponseEntity<List<SupplierApiDetailVO>> listBySupplierIds(List<Long> supplierIds) {
        List<SupplierDetail> supplierDetail = supplierDetailService.listBySupplierIds(supplierIds);
        return ServerResponseEntity.success(mapperFacade.mapAsList(supplierDetail, SupplierApiDetailVO.class));
    }

    @Override
    public ServerResponseEntity<SupplierDetailBO> supplierExtensionData(Long supplierId) {
        return ServerResponseEntity.success(supplierDetailService.supplierExtensionData(supplierId));
    }

    @Override
    public ServerResponseEntity<List<SupplierApiDetailVO>> getSupplierDetailBySupplierIdAndSupplierName(List<Long> supplierIds, String supplierName) {
        return ServerResponseEntity.success(supplierDetailService.getSupplierDetailBySupplierIdAndSupplierName(supplierIds,supplierName));
    }

    @Override
    public ServerResponseEntity<List<SupplierApiDetailVO>> getSupplierDetailBySupplierName(String supplierShopName) {
        return ServerResponseEntity.success(supplierDetailService.getSupplierDetailBySupplierIdAndSupplierName(null,supplierShopName));
    }

    @Override
    public ServerResponseEntity<List<SupplierSimpleBO>> listSimple(SupplierSimpleBO supplierSimpleBO) {
        return ServerResponseEntity.success(supplierDetailService.listSimple(supplierSimpleBO));
    }

    @Override
    public ServerResponseEntity<SupplierApiUserVO> getSupplierUserBySupplierUserId(Long supplierUserId) {
        return ServerResponseEntity.success(mapperFacade.map(supplierUserService.getSimpleByUserId(supplierUserId), SupplierApiUserVO.class));
    }

    @Override
    public ServerResponseEntity<List<Long>> getSupplierIdsBySupplierStatus(Integer supplierStatus) {
        return ServerResponseEntity.success(supplierDetailService.getSupplierIdBySupplierStatus(supplierStatus));
    }

    @Override
    public ServerResponseEntity<List<SupplierApiDetailVO>> listSupplierDetailBySupplierIds(List<Long> supplierIds) {
        return ServerResponseEntity.success(supplierDetailService.listSupplierDetailBySupplierIds(supplierIds));
    }

    @Override
    public ServerResponseEntity<List<Long>> listSupplierIdByShopIdAndSupplierName(Long shopId, String supplierName) {
        SupplierDetailDTO supplierDetailDTO = new SupplierDetailDTO();
        supplierDetailDTO.setSupplierName(supplierName);
        supplierDetailDTO.setSysType(SysTypeEnum.MULTISHOP.value());
        List<SupplierDetailVO> supplierDetailVOList = supplierDetailService.listSupplierByShopId(supplierDetailDTO, shopId);
        return ServerResponseEntity.success(supplierDetailVOList.stream().map(SupplierDetailVO::getSupplierId).collect(Collectors.toList()));

    }
}
